/**
 * @(#)ApkConfigController.java 2016年12月1日
 * Copyright(C) 2016 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;

import com.alibaba.fastjson.JSONObject;
import edu.hziee.common.lang.DateUtil;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.annotation.SystemControllerLog;
import org.jsbd.boss.common.ExportExcel;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.common.ReturnJsonCode;
import org.jsbd.boss.dao.IMiguUsefulConfigDao;
import org.jsbd.boss.domian.ChannelProvinceInfo;
import org.jsbd.boss.domian.InterceptInfo;
import org.jsbd.boss.domian.ProvinceInfo;
import org.jsbd.boss.domian.channel.*;
import org.jsbd.boss.service.*;
import org.jsbd.boss.service.impl.ChannelConfigService;
import org.jsbd.boss.util.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.*;

/**
 *
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Controller
@RequestMapping("/miguUsefulConfig")
public class MiguUsefulConfigController {
    public static final Logger LOGGER = LoggerFactory.getLogger(MiguUsefulConfigController.class);


    @Resource
    private IMiguUsefulConfigDao miguUsefulConfigDao;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    public String list() {
        return "/miguUsefulConfig/configList";
    }

    @RequestMapping(value = "addConfig", method = RequestMethod.GET)
    public String add() {
        return "/miguUsefulConfig/add";
    }

    @RequestMapping(value = "del")
    public void del(MiguUsefulConfig config, HttpServletResponse response) {
        try {
            miguUsefulConfigDao.deleteConfig(config);
            ResponseUtils.responseSuccess(response);
        } catch (Exception e) {
            LOGGER.error("删除出错", e);
            ResponseUtils.responseFailure(response);
        }
    }

    @RequestMapping(value = "saveConfig", method = RequestMethod.POST)
    public void saveConfig(MiguUsefulConfig config, HttpServletResponse response) {
        try {
            miguUsefulConfigDao.insertConfig(config);
            ResponseUtils.responseSuccess(response);
        } catch (Exception e) {
            LOGGER.error("保存出错", e);
            ResponseUtils.responseInfoExists(response);
        }
    }


    @RequestMapping(value = "updateConfig", method = RequestMethod.POST)
    public void updateConfig(MiguUsefulConfig config, HttpServletResponse response) {
        try {
            miguUsefulConfigDao.updateConfig(config);
            ResponseUtils.responseSuccess(response);
        } catch (Exception e) {
            LOGGER.error("修改apk出错", e);
            ResponseUtils.responseFailure(response);
        }
    }

    @RequestMapping(value = "{id}/configUpdate")
    public String configUpdate(MiguUsefulConfig config, Model model) {
        model.addAttribute("config", miguUsefulConfigDao.selectConfig(config));
        return "miguUsefulConfig/updateConfig";
    }


    @RequestMapping(value = "configList", params = "json")
    @ResponseBody
    public Map<String, Object> configPageList(MiguUsefulConfig config) {
        List<MiguUsefulConfig> list = miguUsefulConfigDao.selectList(config);
        Integer total = miguUsefulConfigDao.countOfConfig(config);
        Map map = new HashMap();
        map.put("rows", list);
        map.put("total", total);
        return map;
    }


}
